/**
 * 游记相关 API
 */

import request from './request'

/**
 * 创建游记
 * @param {object} data - 游记数据
 */
export const createTravelNote = (data) => {
  return request({
    url: '/api/travel-notes',
    method: 'post',
    data
  })
}

/**
 * 更新游记
 * @param {number} id - 游记ID
 * @param {object} data - 更新数据
 */
export const updateTravelNote = (id, data) => {
  return request({
    url: `/api/travel-notes/${id}`,
    method: 'put',
    data
  })
}

/**
 * 删除游记
 * @param {number} id - 游记ID
 */
export const deleteTravelNote = (id) => {
  return request({
    url: `/api/travel-notes/${id}`,
    method: 'delete'
  })
}

/**
 * 获取游记详情
 * @param {number} id - 游记ID
 */
export const getTravelNoteDetail = (id) => {
  return request({
    url: `/api/travel-notes/${id}`,
    method: 'get'
  })
}

/**
 * 获取游记列表
 * @param {object} params - 查询参数
 */
export const getTravelNoteList = (params) => {
  return request({
    url: '/api/travel-notes',
    method: 'get',
    params
  })
}

/**
 * 获取我的游记列表
 * @param {object} params - 查询参数
 */
export const getMyTravelNotes = (params) => {
  return request({
    url: '/api/travel-notes/my/list',
    method: 'get',
    params
  })
}

/**
 * 点赞游记
 * @param {number} id - 游记ID
 */
export const likeTravelNote = (id) => {
  return request({
    url: `/api/travel-notes/${id}/like`,
    method: 'post'
  })
}

/**
 * 取消点赞游记
 * @param {number} id - 游记ID
 */
export const unlikeTravelNote = (id) => {
  return request({
    url: `/api/travel-notes/${id}/like`,
    method: 'delete'
  })
}

/**
 * 收藏游记
 * @param {number} id - 游记ID
 */
export const favoriteTravelNote = (id) => {
  return request({
    url: `/api/travel-notes/${id}/favorite`,
    method: 'post'
  })
}

/**
 * 取消收藏游记
 * @param {number} id - 游记ID
 */
export const unfavoriteTravelNote = (id) => {
  return request({
    url: `/api/travel-notes/${id}/favorite`,
    method: 'delete'
  })
}

/**
 * 添加评论
 * @param {number} id - 游记ID
 * @param {object} data - 评论数据
 */
export const addTravelNoteComment = (id, data) => {
  return request({
    url: `/api/travel-notes/${id}/comments`,
    method: 'post',
    data
  })
}

/**
 * 获取评论列表
 * @param {number} id - 游记ID
 * @param {object} params - 查询参数
 */
export const getTravelNoteComments = (id, params) => {
  return request({
    url: `/api/travel-notes/${id}/comments`,
    method: 'get',
    params
  })
}

/**
 * 删除评论
 * @param {number} commentId - 评论ID
 */
export const deleteTravelNoteComment = (commentId) => {
  return request({
    url: `/api/travel-notes/comments/${commentId}`,
    method: 'delete'
  })
}

/**
 * 获取用户收藏的游记列表
 * @param {object} params - 查询参数
 */
export const getFavoriteTravelNotes = (params) => {
  return request({
    url: '/api/travel-notes/favorite/list',
    method: 'get',
    params
  })
}

/**
 * 获取用户点赞的游记列表
 * @param {object} params - 查询参数
 */
export const getLikeTravelNotes = (params) => {
  return request({
    url: '/api/travel-notes/like/list',
    method: 'get',
    params
  })
}

/**
 * 增加游记浏览量（埋点）
 * @param {number} id - 游记ID
 */
export const increaseTravelNoteView = (id) => {
  return request({
    url: `/api/travel-notes/${id}/view`,
    method: 'post'
  })
}
